#!/usr/bin/env python
#coding=utf-8

import wx


class Panels(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)

        self.vbox = wx.BoxSizer(wx.VERTICAL)
        panel = wx.Panel(self,-1)
        hbox= wx.BoxSizer(wx.HORIZONTAL)
        b1 = wx.Button(panel, -1, 'Button 1 add')
        b2 = wx.Button(panel, -1, 'Button 2 remove')
        hbox.Add(b1,-1,wx.ALL,10)
        hbox.Add(b2,-1,wx.ALL,10)
        panel.SetSizer(hbox)

        panel2 = wx.Panel(self,-1)
        hbox2= wx.BoxSizer(wx.HORIZONTAL)
        b1_2 = wx.Button(panel2, -1, 'Button 3 add')
        b2_2 = wx.Button(panel2, -1, 'Button 4 remove')
        hbox2.Add(b1_2,-1,wx.ALL,10)
        hbox2.Add(b2_2,-1,wx.ALL,10)
        panel2.SetSizer(hbox2)
        self.vbox.Add(panel,-1,wx.EXPAND,10)
        self.vbox.Add((-1, 10))
        self.vbox.Add(panel2,-1,wx.EXPAND,10)


        self.SetSizer(self.vbox)
        self.Layout()
        
        self.Bind(wx.EVT_BUTTON,self.tstadd, b1)
        self.Bind(wx.EVT_BUTTON,self.tstremove, b2)
        self.Bind(wx.EVT_BUTTON,self.tstadd, b1_2)
        self.Bind(wx.EVT_BUTTON,self.tstremove, b2_2)        

        self.Centre()

        self.Show(True)

    def tstadd(self,event):
        panel3 = wx.Panel(self,-1)
        hbox3= wx.BoxSizer(wx.HORIZONTAL)
        b1_3 = wx.Button(panel3, -1, 'Button 5 add')
        b2_3 = wx.Button(panel3, -1, 'Button 6 remove')
        hbox3.Add(b1_3,-1,wx.ALL,10)
        hbox3.Add(b2_3,-1,wx.ALL,10)
        panel3.SetSizer(hbox3)
        self.vbox.Add((-1, 10))
        self.vbox.Add(panel3,-1,wx.EXPAND,10)
        self.SetSizer(self.vbox)
        self.Layout()
        self.Bind(wx.EVT_BUTTON,self.tstadd, b1_3)
        self.Bind(wx.EVT_BUTTON,self.tstremove, b2_3)        
        return
    
    def tstremove(self,event):
        event.GetEventObject().GetParent().Destroy()
        self.Layout()    
        
app = wx.App()
Panels(None, -1, 'Panels')
app.MainLoop()
